﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using fqlmoney.Common;
using fqlmoney.Model;
using fqlmoney.BLL;
using System.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Web.Filter;
using Web.Models;

namespace Web.Controllers
{
    public class HomeController : Controller
    {

        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        [CheckAdminLogin]
        public ActionResult Index(string date,int type)
        {
            OrderBLL bll = new OrderBLL();
            MoneyTypeBLL moneybll = new MoneyTypeBLL();
            userinfo model_userinfo =BaseOperater.getAdmin(HttpContext);
            string strdate = DateTime.Now.ToString("yyyy-MM");
            
            if (!string.IsNullOrEmpty(date))
            {
                strdate = Utils.StrToDateTime(date, DateTime.Now).ToString("yyyy-MM");
            }
            ViewBag.date = strdate;
            ViewBag.userinfo = model_userinfo;
            List<dynamic> data= bll.GetPieData(model_userinfo.u_id, strdate, type);
            string piedata = "";
            decimal totalprice = 0;
            if(data.Count>0)
            {
                for (int i = 0; i < data.Count; i++)
                {
                    if (piedata != "")
                    {
                        piedata += ",";
                    }
                    piedata += "{value:" +Utils.ObjectToStr(data[i].amount) + ", name:'" + Utils.ObjectToStr(data[i].t_name) + "'}";
                    totalprice += Utils.ObjToDecimal(data[i].amount,0);
                }
            }
            else
            {
                piedata += "{value:100, name:'无数据'}";
            }
            ViewBag.piedata = piedata;
            ViewBag.totalprice = totalprice;
            ViewBag.typelist = moneybll.GetList(model_userinfo.u_id);
            return View();
        }

    }
}